<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * BackendPro
 *
 * A website backend system for developers for PHP 4.3.2 or newer
 *
 * @package         conlabz CMS
 * @author          Christian Schneider
 * @copyright       Copyright (c) 2009
 * @license         
 * @link            http://www.conlabz.de
 * @filesource
 */

// ---------------------------------------------------------------------------

/**
 * Language_model
 *
 * Model used to retrive languages
 *
 * @package			conlabz CMS
 * @subpackage		Models
 */
class Language_model extends Base_model {
	function Language_model( ) {
		parent::Base_model( );

		$this->_TABLES = array( 'Option' => $this->config->item( 'backendpro_table_prefix' ) . 'article' );

		// Cache to store already fetched items
		$this->_CACHE = array( );

		// Object keyword
		// I wouldn't advise changing this, it could corrupt current
		// articles, the reason for needing this is to stop unserialze
		// errors spamming the log files
		$this->object_keyword = "BeP::Object::";

		log_message( 'debug', 'conlabz CMS : Language_model class loaded' );
	}

	/**
	 * Get Language
	 *
	 * @access public
	 * @param mixed $where Where query string/array
	 * @param array $limit Limit array including offset and limit values
	 * @return object
	 */
	function getLanguages( $where = NULL, $limit = array( 'limit' => NULL, 'offset' => '' ) ) {
		$this->db->select( 'language.id,
							language.name,
							language.code'
						   );
		$this->db->from( "language" );
		if( !is_null( $where ) ){
			$this->db->where( $where );
		}
		if( !is_null( $limit['limit'] ) ){
			$this->db->limit( $limit['limit'], ( isset( $limit['offset'] ) ? $limit['offset'] : '' ) );
		}
		return $this->db->get( );
	}
	
	/**
	 * Constructs an array of the given languages to be used for a dropdown menu
	 *
	 * @access public
	 * @return array
	 */
	function buildLanguageDropdown( ) {
		$languages = $this->getLanguages( );
		
		$dropdown = array( );
		foreach( $languages->result( ) as $row ) {
	    	 $dropdown[$row->id] = $row->name;
		}
		
		return $dropdown;
	}
}
/* End of file language_model.php */
/* Location: ./modules/articles/models/language_model.php */